#include <string>
#include <iostream>
#include <vector>
#include <memory.h>
using namespace std;

bool vis[55];
string buff;
int minx, mxc, n, nowp;
vector<int> G[55];

template<typename T>
void del(vector<T> &v, unsigned p) {
	swap(v[p], v[v.size()-1]);
	v.pop_back();
} 

void getchar_(char *c) {
	*c = buff[nowp++];
}

void read(int x) {
	char c;
	int now;
	while (1) {
		getchar_(&c);
		if ('0' <= c && c <= '9') {
			int res = 0;
			while ('0' <= c && c <= '9') {
				res *= 10;
				res += c - '0';
				getchar_(&c);
			}
			now = res;
			G[x].push_back(now);
			G[now].push_back(x);
			++n;
		} 
		if (c == ')') return;
		else if (c == '(') {
			read(now);
		}
	}
}

int isleave(int x) {
	int sum = 0;
	int fp = -1;
	for (unsigned i = 0; i < G[x].size(); ++i) {
		if (!vis[G[x][i]]) {++sum; if (fp == -1) {fp = i;} }
	}
	return sum == 1 ? fp : -1;
}

int main() {
	char c;
	int root;
	while (getline(cin, buff)) {
		buff += '\n';
		getchar_(&c);
		if (c == '\n') goto RESET;
		getchar_(&c);
		root = 0;
		while ('0' <= c && c <= '9') {
			root *= 10;
			root += c - '0';
			getchar_(&c);
		}
		n = 1;
		while (1) {
			getchar_(&c);
			if (c == '\n') break;
			else if (c == '(') read(root);
		}

		for (int i = 1; i < n; ++i) {
			//for (int j = 1; j <= n; ++j) cout << vis[j] << " ";
			//cout << endl;
			for (int x = 1; x <= n; ++x) {
				int fp;
				if (vis[x]) continue;
				if ((fp = isleave(x)) != -1) {
					cout << G[x][fp] << " ";
					vis[x] = 1;
					break;
				}
			}
		}
		cout << endl;

		RESET:
		for (int i = 0; i <= n; ++i) {
			G[i].clear();
		}
		buff = "";
		nowp = 0;
		memset(vis, 0, sizeof(vis));
	}
	return 0;
}